/*
 * @Author: your name
 * @Date: 2024-04-21 10:36:51
 * @LastEditTime: 2024-04-21 10:57:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\222.完全二叉树的节点个数.cpp
 */
/*
 * @lc app=leetcode.cn id=222 lang=cpp
 *
 * [222] 完全二叉树的节点个数
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int getNUm(TreeNode* root){
        if(!root){
            return 0;
        }
        int left = getNUm(root->left);
        int right = getNUm(root->right);
        return left+right+1;

    }
    int countNodes(TreeNode* root) {
        return getNUm(root);
    }
};
// @lc code=end
// 递归或者层序遍历都是ok的
// 这样的解法没有抓住完全二叉树的特点
